function two_char(n) {
    return n >= 10 ? n : "0" + n;
}
function time_fun() {
    var sec=0;
    var flag=1;
    var timeId  = setInterval(function () {
        sec++;
        var date = new Date(0, 0)
        date.setSeconds(sec);
        var h = date.getHours(), m = date.getMinutes(), s = date.getSeconds();
        document.getElementById("mytime").innerText = two_char(h) + ":" + two_char(m) + ":" + two_char(s);
        if(two_char(m)>=60){
            clearInterval(timeId);
            var questionArray = new Array("Q1","Q2","Q3","Q4","Q5","Q6","Q7","Q8","Q9","Q10");
            var resultArray = new Array();
            var rightArray = new Array();

            //aryAns[]是从后端返回的数组,当点击交卷的时候,向后端请求正确答案的数组,赋值给aryAns[]即可;
            var aryAns = new Array(4,1,4,1,2,4,4,3,4,1);   //建立储存正确答案的数组
            for (var i = 0; i < questionArray.length; i++) {
                if (Name(questionArray[i])!=10) {
                    resultArray[i] = Name(questionArray[i]);
                }
            }
            var right_number= 0;//计算答对的题数；
            for (var i = 0; i < questionArray.length; i++) {
                if (aryAns[i]==resultArray[i]) {
                    right_number++;
                    rightArray[i] = 1;
                }else{
                    rightArray[i] = 0;
                }
            }
            var right_question = " ";
            var error_question = " ";
            for (var i = 0; i < rightArray.length; i++) {
                if (rightArray[i] ==1 ) {
                    right_question += i+1+",";
                }else{
                    error_question += i+1+",";
                }
            }
            var time=document.getElementById("mytime").innerHTML;
            document.getElementById("right_number").innerText = right_number;
            document.getElementById("time").innerText = time;
            if (right_question!=" ") {
                document.getElementById("right_question").innerText = right_question;

            }
            if (error_question!=" ") {
                document.getElementById("error_question").innerText = error_question;

            }
            document.getElementById("answer").style.display="block";
        }
    }, 1000);

}

function main(){

    var questionArray = new Array("Q1","Q2","Q3","Q4","Q5","Q6","Q7","Q8","Q9","Q10");
    var resultArray = new Array();
    var rightArray = new Array();

    //aryAns[]是从后端返回的数组,当点击交卷的时候,向后端请求正确答案的数组,赋值给aryAns[]即可;
    var aryAns = new Array(4,1,4,1,2,4,4,3,4,1);   //建立储存正确答案的数组
    for (var i = 0; i < questionArray.length; i++) {
        if (Name(questionArray[i])!=10) {
            resultArray[i] = Name(questionArray[i]);
        }else{
            alert("第"+(i+1)+"题,您未作答!!");
            return false;
        }
    }
    var right_number= 0;//计算答对的题数；
    for (var i = 0; i < questionArray.length; i++) {
        if (aryAns[i]==resultArray[i]) {
            right_number++;
            rightArray[i] = 1;
        }else{
            rightArray[i] = 0;
        }
    }
    var right_question = " ";
    var error_question = " ";
    for (var i = 0; i < rightArray.length; i++) {
        if (rightArray[i] ==1 ) {
            right_question += i+1+",";
        }else{
            error_question += i+1+",";
        }
    }
    var time=document.getElementById("mytime").innerHTML;
    document.getElementById("right_number").innerText = right_number;
    document.getElementById("time").innerText = time;
    if (right_question!=" ") {
        document.getElementById("right_question").innerText = right_question;

    }
    if (error_question!=" ") {
        document.getElementById("error_question").innerText = error_question;

    }
    document.getElementById("answer").style.display="block";
};

function Name(name)
{
    var temp = document.getElementsByName(name);
    var intHot = 9;
    for(var i=0;i<temp.length;i++)
    {
        if(temp[i].checked)
            intHot = temp[i].value;
    }
    if (intHot==9) {
        return 10;
    }
    return intHot;
};